package pc2brick;
import java.io.File;

import lejos.nxt.*;

// stop when touched or less than 10 centimeters
public class forback 
{
	public static void main(String[] args) throws Exception 
	{
		TouchSensor touchWall = new TouchSensor(SensorPort.S4);
		TouchSensor touchTail = new TouchSensor(SensorPort.S1);
		//UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S2);
		//int distance;
		boolean status = false;
		boolean change = true;
		
		
		
		while(!touchTail.isPressed())
		{
			if (change)
			{
				LCD.clear();
				
				Sound.playSample(new File("stop.wav"));
				
				while (touchWall.isPressed())
				{
					Motor.A.stop();
					Motor.C.stop();
					
					LCD.drawString("stop", 0, 1);
				}
				
				status = !status;
				
				//distance = sonic.getDistance();
				
				//LCD.drawInt(distance, 0, 0);
				
				if (status)
				{
					Sound.playSample(new File("forward.wav"));
					
					LCD.drawString("avance", 0, 1);
					Motor.A.forward();
					//Motor.B.forward();
					Motor.C.forward();
					//Motor.B.forward();
				}else{
					Sound.playSample(new File("backward.wav"),100);
					
					Motor.A.backward();
					//Motor.B.stop();
					Motor.C.backward();
					LCD.drawString("recule", 0, 1);
				}
				
				change = false;
			}
			
			if (touchWall.isPressed())
			{
				change = true;
				
				
			}
		}
	}
}
